package com.jyu.hakkatranslation.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jyu.hakkatranslation.mapper.UserMapper;
import com.jyu.hakkatranslation.pojo.User;
import com.jyu.hakkatranslation.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 注册
     * @param user
     * @return
     */
    @Override
    public boolean register(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",user.getUsernames());
        User user1 = userMapper.selectOne(queryWrapper);
        if(user!=null){//如果已经存在
            return false;
        }else {
            int insert = userMapper.insert(user1);
            return true;
        }
    }

    /**
     * 登录功能
     * @param usernames
     * @param password
     * @return
     */
    @Override
    public boolean login(String usernames, String password) {
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("usernames",usernames)
                .eq("password",password);
        List<User> users = userMapper.selectList(queryWrapper);
        if(users==null){
            return false;
        }else{
            return true;
        }
    }
}
